package com.shexianyu.simple;

/**
 * 283 移动零
 */
public class MoveZeroes {
    public void moveZeroes(int[] nums) {
        //索引
        int index = 0;
        //将数组中不为零的值按顺序存储
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != 0) {
                nums[index++] = nums[i];
            }
        }
        //判断索引是否等于数组长度，若不等则补0
        while (index < nums.length) {
            nums[index++] = 0;
        }
    }
}
